import apiClient from "../apiClient";

import type { UserInfo, UserToken } from "#/entity";
import { getToken } from "@/utils/auth";
export interface SignInReq {
	username: string;
	password: string;
	sysCode: string;
}

export interface SignUpReq extends SignInReq {
	email: string;
}
export type SignInRes = UserToken & { user: UserInfo };

export enum UserApi {
	SignIn = "/auth/cms/login",
	Logout = "/auth/cms/logout",
	UserInfo = "/auth/cms/info",
}

const signin = (data: SignInReq) => apiClient.post<SignInRes>({ url: UserApi.SignIn, data });
const logout = () => apiClient.get({ url: UserApi.Logout, params: { token: getToken() } });
const getUserInfo = () => apiClient.get<UserInfo[]>({ url: UserApi.UserInfo });

export default {
	signin,
	logout,
	getUserInfo,
};

